//引入
var util = require("./utils/login.js"); 

//配置文件
var config = require("./config/basicsConfig.js");

// app.js
App({
  data: {
    token: null,
  },
  onLaunch() {
    //console.log('初始化');
    this.basicsConstantConfig();
    this.getLoginInfo();
  },

  //用户登录信息
  getLoginInfo(){
    let token = wx.getStorageSync('token');
    if(token != ''){
      wx.request({
        url: config.basics.website + config.requesturls.getuserinfo,
        method: 'POST',
        header: { 'content-type': 'application/x-www-form-urlencoded',},
        data: {'token': wx.getStorageSync('token'),},
        success: (res) => {
          //验证token
          let verificationToken = util.log.verificationToken(res.data);
          if (verificationToken == true) {
            //token没有过期执行
            util.log.getuser();
          }
        },
      })
    }
    //console.log(this.globalData);
  },

  //配置全局变量
  basicsConstantConfig(){
    //初始化商品信息，后期修改后台商品
    var config = require("/data/config.js");
    this.globalData.shopInfo = config.configData;
    
    //项目配置文件
    var basicsConfig = require("/config/basicsConfig.js");
    //appid
    this.globalData.appId = basicsConfig.basics.appId;
    //appSecret
    this.globalData.appSecret = basicsConfig.basics.appSecret;
    //访问地址
    this.globalData.website = basicsConfig.basics.website;
  },

  globalData: {
    userInfo: null,
    token: null,
    shop_id: 1,
    shopInfo: {
      index_recommend_title: '优选水果',
    },
    appId: null,
    appSecret: null,
    website: null,
  },

});